class Solution(object):
    def isValid(self, s):
        """
        :type s: str
        :rtype: bool
        """
        stack=[]
        for i in range(0,len(s)):
            if s[i] == "{" or s[i] == "[" or s[i] == "(" :
                stack.append(s[i])
            elif s[i] == "}":
                if len(stack) ==0:
                    return False
                temp = stack.pop()
                if temp != "{":
                    return False
            elif s[i] == "]":
                if len(stack) ==0:
                    return False
                temp = stack.pop()
                if temp != "[":
                    return False
            elif s[i] == ")":
                if len(stack) ==0:
                    return False
                temp = stack.pop()
                if temp != "(":
                    return False
        return len(stack) == 0


t = Solution()
print(t.isValid("()"))